/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entidades;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author ccedeno
 */
@Entity
@Table(name = "interes_area", catalog = "emilima_tradoc", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "InteresArea.findAll", query = "SELECT i FROM InteresArea i"),
    @NamedQuery(name = "InteresArea.findByIdInter", query = "SELECT i FROM InteresArea i WHERE i.interesAreaPK.idInter = :idInter"),
    @NamedQuery(name = "InteresArea.findByIdIntArea", query = "SELECT i FROM InteresArea i WHERE i.interesAreaPK.idIntArea = :idIntArea"),
    @NamedQuery(name = "InteresArea.findByNombre", query = "SELECT i FROM InteresArea i WHERE i.nombre = :nombre"),
    @NamedQuery(name = "InteresArea.findByCorrela", query = "SELECT i FROM InteresArea i WHERE i.correla = :correla")})
public class InteresArea implements Serializable {

    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected InteresAreaPK interesAreaPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 245)
    @Column(name = "nombre", nullable = false, length = 245)
    private String nombre;
    @Size(max = 8)
    @Column(name = "correla", length = 8)
    private String correla;
    @JoinColumn(name = "estado", referencedColumnName = "id_estado", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Estado estado;
    @JoinColumn(name = "id_inter", referencedColumnName = "id_inter", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Interesado interesado;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "interesArea", fetch = FetchType.LAZY)
    private List<Expediente> expedienteList;

    public InteresArea() {
    }

    public InteresArea(InteresAreaPK interesAreaPK) {
        this.interesAreaPK = interesAreaPK;
    }

    public InteresArea(InteresAreaPK interesAreaPK, String nombre) {
        this.interesAreaPK = interesAreaPK;
        this.nombre = nombre;
    }

    public InteresArea(String idInter, String idIntArea) {
        this.interesAreaPK = new InteresAreaPK(idInter, idIntArea);
    }

    public InteresAreaPK getInteresAreaPK() {
        return interesAreaPK;
    }

    public void setInteresAreaPK(InteresAreaPK interesAreaPK) {
        this.interesAreaPK = interesAreaPK;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getCorrela() {
        return correla;
    }

    public void setCorrela(String correla) {
        this.correla = correla;
    }

    public Estado getEstado() {
        return estado;
    }

    public void setEstado(Estado estado) {
        this.estado = estado;
    }

    public Interesado getInteresado() {
        return interesado;
    }

    public void setInteresado(Interesado interesado) {
        this.interesado = interesado;
    }

    @XmlTransient
    public List<Expediente> getExpedienteList() {
        return expedienteList;
    }

    public void setExpedienteList(List<Expediente> expedienteList) {
        this.expedienteList = expedienteList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (interesAreaPK != null ? interesAreaPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof InteresArea)) {
            return false;
        }
        InteresArea other = (InteresArea) object;
        if ((this.interesAreaPK == null && other.interesAreaPK != null) || (this.interesAreaPK != null && !this.interesAreaPK.equals(other.interesAreaPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
//        return "Entidades.InteresArea[ interesAreaPK=" + interesAreaPK + " ]";
//        return  interesAreaPK +" "+nombre;
        return interesAreaPK.getIdInter()+" "+interesado.getNombres() + ", "+interesAreaPK.getIdIntArea()+" " + nombre;
    }
}
